package com.example.demo.controller;

import com.example.demo.controller.data.ReturnData;
import com.example.demo.entity.Circle;
import com.example.demo.entity.CircleLike;
import com.example.demo.entity.Comment;
import com.example.demo.entity.User;
import com.example.demo.service.CircleService;
import com.example.demo.utils.TokenUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 圈子相关的 接口控制类
 */
@RestController
@RequestMapping("/circle")
public class CircleController {
    @Resource
    CircleService circleService;

    /**
     * 分页获取圈子列表
     * @param page 页码
     * @param pageSize 每一页的长度
     * @return
     */
    @GetMapping("/list")
    public ReturnData list(@RequestParam(defaultValue = "1") int page,
                           @RequestParam(defaultValue = "20")int pageSize,
                           HttpServletRequest request){
        String token = request.getHeader("token");//取Token
        return circleService.getList(page,pageSize,token);
    }

    /**
     * 分页获取当前登录用户的圈子列表
     * @param page 页码
     * @param pageSize 每一页的长度
     * @return
     */
    @GetMapping("/myList")
    public ReturnData myList(@RequestParam(defaultValue = "1") int page,
                             @RequestParam(defaultValue = "20")int pageSize,
                             HttpServletRequest request){
        String token = request.getHeader("token");//取Token
        return circleService.myList(page,pageSize,token);
    }

    /**
     * 发布圈子接口
     * @param request
     * @param circle
     * @return
     */
    @PostMapping("/add")
    public ReturnData add(HttpServletRequest request,@RequestBody Circle circle){
        String token = request.getHeader("token");//取Token
        return circleService.add(token,circle);
    }

    /**
     * 点赞或取消点赞圈子的接口
     * @param request
     * @param circleLike
     * @return
     */
    @PostMapping("/like")
    public ReturnData like(HttpServletRequest request,@RequestBody CircleLike circleLike){
        String token = request.getHeader("token");//取Token
        return circleService.like(token,circleLike);
    }

    /**
     * 分页获取当前登录用户的点赞圈子列表
     * @param page 页码
     * @param pageSize 每一页的长度
     * @return
     */
    @GetMapping("/myLikeList")
    public ReturnData myLikeList(@RequestParam(defaultValue = "1") int page,
                                 @RequestParam(defaultValue = "20")int pageSize,
                                 HttpServletRequest request){
        String token = request.getHeader("token");//取Token
        return circleService.myLikeList(page,pageSize,token);
    }
    /**
     * 获取某条圈子的点赞用户昵称列表
     * @param id 圈子的id
     * @return
     */
    @GetMapping("/getLikeUsers")
    public ReturnData getLikeUsers(int id){
        return circleService.getLikeUsers(id);
    }

    /**
     * 删除圈子的接口
     * @param request
     * @param circle
     * @return
     */
    @PostMapping("/delete")
    public ReturnData delete(HttpServletRequest request,@RequestBody Circle circle){
        String token = request.getHeader("token");//取Token
        return circleService.delete(token,circle);
    }

    /**
     * 评论接口
     * @param request
     * @param comment
     * @return
     */
    @PostMapping("/comment")
    public ReturnData comment(HttpServletRequest request,@RequestBody Comment comment){
        String token = request.getHeader("token");//取Token
        return circleService.comment(token,comment);
    }
    /**
     * 获取某条圈子的评论列表数据
     * @param id 圈子的id
     * @return
     */
    @GetMapping("/getCommentList")
    public ReturnData getCommentList(int id){
        return circleService.getCommentList(id);
    }

    /**
     * 删除评论接口
     * @param request
     * @param comment
     * @return
     */
    @PostMapping("/delComment")
    public ReturnData delComment(HttpServletRequest request,@RequestBody Comment comment){
        String token = request.getHeader("token");//取Token
        return circleService.delComment(token,comment);
    }


}
